//
// Created by liz on 24-11-8.
//

#ifndef HE_SERIAL_SERVO_H
#define HE_SERIAL_SERVO_H


#include "bsp_usart.h"
#include "bsp_pwm.h"

#define SERVO_MOTOR_CNT 10
#define SERVO_MAX_BUFF 10

typedef enum
{
    SERVO_BUS,
    SERVO_PWM,
}SERVO_TYPE_e;

typedef enum {
    READ_TEMP,
    READ_VIN,
    READ_POS
}SERVO_READ_TYPE;



//@todo:应该让所有舵机共用
typedef struct
{
    PWM_Init_Config_s pwm_init_config;
    UART_HandleTypeDef *usart_handle;
    uint8_t servo_id;
    SERVO_TYPE_e servo_type;

    float angle_min,angle_max;          //PWM舵机用的

}Servo_Init_Config_s;

typedef struct
{
    uint8_t servo_id;

    uint8_t servo_temp;             //温度原始值
    uint16_t servo_vin;
    uint8_t servo_en;
    uint8_t servo_mode;
    int16_t current_pos;            //收到的当前角度值

    PWMInstance *pwm_instance;
    USARTInstance *usart_instance;
    SERVO_TYPE_e servo_type;

    float angle;

    float angle_min,angle_max;          //PWM舵机用的

}ServoInstance;

ServoInstance *HE_ServoInit(Servo_Init_Config_s *Servo_Init_Config);
void HE_ServoSetAngle(ServoInstance *servo, float angle,uint16_t move_time,uint8_t synchronous);
void HE_ServoRead(ServoInstance *servo, SERVO_READ_TYPE read_type);

#endif //HE_SERIAL_SERVO_H
